﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using DualControl.Controllers;
using DualControl.HazardSources;
using DualControl.HazardSources.Dtos;
using DualControl.RiskPoints;
using DualControl.RiskPoints.Dtos;
using Microsoft.AspNetCore.Mvc;
using X.PagedList;

namespace DualControl.Web.Mvc.Controllers
{
    public class HazardSourceController : DualControlControllerBase
    {

        private readonly IRiskPointAppService _riskPointAppService;

        private readonly IHazardSourceAppService _hazardSourceAppService;

        public HazardSourceController(HazardSourceAppService hazardSourceAppService,
            IRiskPointAppService riskPointAppService)
        {
            _hazardSourceAppService = hazardSourceAppService;
            _riskPointAppService = riskPointAppService;
        }

        public async Task<ActionResult> Index( int page,string view)      
        {

            int pagenumber = page < 1 ? 1 : page;
            GetRiskPointsInput input = new GetRiskPointsInput
            {
                SkipCount = (pagenumber - 1) * AppConsts.DefaultPageSize,
                MaxResultCount = AppConsts.DefaultPageSize
            };
            var result = await _hazardSourceAppService.GetPagedRiskPoints(input);
            var PageOfRiskPointListDto = new StaticPagedList<RiskPointListDto>(result.Items, pagenumber, AppConsts.DefaultPageSize, result.TotalCount);
            //将分页结果放入ViewBag供View使用
            ViewBag.PageOfRiskPointListDto = PageOfRiskPointListDto;   

            return View(view);            
        }
      
    }
}